var _o85;
var cc__decorate = __decorate;
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.RankMgr = undefined;
var $2constant = require("constant");
var $2GameUser = require("GameUser");
var $2GameEvent = require("GameEvent");
var cc__decorator = cc._decorator;
var ccp_ccclass = cc__decorator.ccclass;
var ccp_property = cc__decorator.property;
var exp_RankMgr = _o85 = /* */function () {
  function _ctor() {
    babel_classCallCheck(this, _ctor);
    this._tempScoreList = {};
  }
  return babel_createClass(_ctor, [{
    key: "putScore",
    value: function putScore(e, t) {
      return new Promise(function (n) {
        console.log("上传分数", $2constant.RANKTYPE[e], t, $2GameUser.default.getInstance().icon);
        if ($2GameUser.default.getInstance().icon && $2GameUser.default.getInstance().id) {
          console.log("开始上传分数", $2GameUser.default.getInstance().openid);
          if ("" != $2GameUser.default.getInstance().openid) {
            var _o86 = {};
            _o86[$2constant.RANKTYPE[e]] = t;
            console.log("上传分数dt:", _o86);
            $2GameEvent.default.sendEvent("putscore", {
              data: _o86,
              id: $2GameUser.default.getInstance().id,
              openid: $2GameUser.default.getInstance().openid,
              uid: $2GameUser.default.getInstance().uid,
              name: $2GameUser.default.getInstance().name,
              icon: $2GameUser.default.getInstance().icon
            }, function (e) {
              console.log("排行榜信息上传成功", e);
              n();
            });
          }
        } else {
          console.log("上传分数失败，授权后才可以上传分数");
        }
      });
    }
  }, {
    key: "getScore",
    value: function getScore(e) {
      var _this78 = this;
      console.log("getInstance:", $2GameUser.default.getInstance());
      var t = ["day", "week", "month", "day_yjwj", "week_yjwj", "month_yjwj"];
      console.log("strs[type]:", t[e]);
      return new Promise(function (n) {
        $2GameEvent.default.sendEvent("getscorelist", {
          type: t[e],
          id: $2GameUser.default.getInstance().id,
          openid: $2GameUser.default.getInstance().openid,
          uid: $2GameUser.default.getInstance().uid,
          name: $2GameUser.default.getInstance().name,
          icon: $2GameUser.default.getInstance().icon
        }, function (t) {
          console.log("fetch rank data success: ", t);
          if (t.data && t.data.data) {
            _this78.updateScoreList(t.data.data, e);
          } else {
            _this78.updateScoreList(null, e);
          }
          n(_this78._tempScoreList[$2constant.RANKTYPE[e]]);
        });
      });
    }
  }, {
    key: "updateScoreList",
    value: function updateScoreList(e, t) {
      null == e && (e = []);
      var n = false;
      for (var _o90 = 0; _o90 < e.length; _o90++) {
        if (null != e[_o90].data) {
          e[_o90].iself = false;
          e[_o90].id == $2GameUser.default.getInstance().id && (n = true);
          e[_o90].type = $2constant.RANKTYPE[t];
        } else {
          e.splice(_o90, 1);
          _o90--;
        }
      }
      for (var _o91 = e.length - 1; _o91 >= 0; _o91--) {
        e[_o91].icon;
      }
      e.sort(function (e, n) {
        return n.data[$2constant.RANKTYPE[t]] - e.data[$2constant.RANKTYPE[t]];
      });
      e.length > 100 && e.pop();
      this._tempScoreList[$2constant.RANKTYPE[t]] = e;
      console.log("临时的分数排行 --- 状态更新：", this._tempScoreList);
    }
  }, {
    key: "getlastScore",
    value: function getlastScore(e) {
      return this._tempScoreList[$2constant.RANKTYPE[e]];
    }
  }, {
    key: "getOtherScore",
    value: function getOtherScore(e) {
      console.log("getOtherScore uid", e);
      return new Promise(function (t) {
        $2GameEvent.default.sendEvent("getscore", {
          ids: [e]
        }, function (e) {
          t(e);
        });
      });
    }
  }, {
    key: "setOtherScore",
    value: function setOtherScore(e, t, n) {
      var _o89 = {};
      _o89[$2constant.RANKTYPE[e]] = n;
      $2GameEvent.default.sendEvent("changescore", {
        data: _o89,
        id: t
      }, function (e) {
        console.log("changescore res:", e);
      });
    }
  }], [{
    key: "instance",
    get() {
      null == this._instance && (this._instance = new _o85());
      return this._instance;
    }
  }]);
}();
exp_RankMgr._instance = null;
exp_RankMgr = _o85 = cc__decorate([ccp_ccclass("RankMgr")], exp_RankMgr);
exports.RankMgr = exp_RankMgr;